package com.cskt.itripbiz.comtroller;

import com.cskt.common.constants.ErrorCodeEnum;
import com.cskt.common.vo.*;
import com.cskt.itripbiz.service.AreaDicService;
import com.cskt.itripbiz.service.HotelService;
import com.cskt.itripbiz.service.ImageService;
import com.cskt.itripbiz.service.LabelDicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.util.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/api/hotel")
@Api(tags = "酒店控制器")
public class HotelController {
    private static final Logger log = LoggerFactory.getLogger(HotelController.class);
    @Resource
    private HotelService hotelService;
    @Resource
    private AreaDicService areaDicService;
    @Resource
    private LabelDicService labelDicService;
    @Resource
    private ImageService imageService;
    /*** 查询热门城市接口 * @param type * @return */
    @ApiOperation(value = "查询热门城市", httpMethod = "GET", protocols = "HTTP", produces =MediaType.APPLICATION_JSON_VALUE, response = ReturnResult.class,
            notes = "查询国内、国外的热门城市(1:国内 2:国外)" +
                    "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下： </p>" +
                    "<p>错误码：</p>" + "<p>10201 : hotelId不能为空 </p>" + "<p>10202 : 系统异常,获取失败</p>")
    @RequestMapping(value = "/queryhotcity/{type}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public ReturnResult queryHotCity(
            @ApiParam(name="type",value = "国内\\国外",type = "path")

            @PathVariable("type") Integer type) {
        if (StringUtils.isEmpty(type)) {
            //如果参数为空
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        List<AreaDicVO> areaDicVOList = areaDicService.findAreaDicVOByType(type);
        if (org.apache.shiro.util.CollectionUtils.isEmpty(areaDicVOList)) {
            //数据为空
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        return ReturnResult.ok(areaDicVOList);
    }
    //查询商圈接口
    @ApiOperation(value = "查询商圈", httpMethod = "GET", protocols = "HTTP", produces = "application/json",
            response = ReturnResult.class,
            notes = "根据城市查询商圈" +
                    "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>"
                    + "<p>错误码：</p>" + "<p>10203 : cityId不能为空 </p>"
                    + "<p>10204 : 系统异常,获取失败</p>")
    @RequestMapping(value = "/querytradearea/{cityId}" + "", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult queryTradeArea(@PathVariable Long cityId) {
        if (StringUtils.isEmpty(cityId)) {
            //如果参数为空
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        List<AreaDicVO> areaDicVOList = areaDicService.findAreaDicVOByCityId(cityId);
        if (org.apache.shiro.util.CollectionUtils.isEmpty(areaDicVOList)) {
            //数据为空
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        return ReturnResult.ok(areaDicVOList);
    }
    //查询酒店特色列表
    @ApiOperation(value = "查询酒店特色列表", httpMethod = "GET", protocols = "HTTP",
            produces = "application/json", response = ReturnResult.class,
            notes = "获取酒店特色(用于查询页列表)" + "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>"
                    + "<p>错误码: </p>" + "<p>10205: 系统异常,获取失败</p>")
    @RequestMapping(value = "/queryhotelfeature", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public ReturnResult queryHotelFeature() {
        List<LabelDicVO> labelDicVOList = labelDicService.findLabelDicVO();
        if (org.apache.shiro.util.CollectionUtils.isEmpty(labelDicVOList)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        return ReturnResult.ok(labelDicVOList);
    }
    //根据酒店Id查询酒店设施
    @ApiOperation(value = "根据酒店id查询酒店设施", httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = ReturnResult.class, notes = "根据酒店id查询酒店设施")
    @ApiImplicitParam(required = true, name = "id", value = "酒店ID",paramType = "path")
    @RequestMapping(value = "/queryhotelfacilities/{id}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    public ReturnResult queryHotelFacilities( @PathVariable Long id) {
        if (StringUtils.isEmpty(id)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        SearchFacilitiesHotelVO facilitiesHotelVO = hotelService.getHotelFacilitiesById(id);
        if (StringUtils.isEmpty(facilitiesHotelVO)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        return ReturnResult.ok(facilitiesHotelVO);
    }
    //根据酒店id查询酒店政策
    @ApiOperation(value = "根据酒店id查询酒店政策", httpMethod = "GET", protocols = "HTTP", produces = "application/json", response = ReturnResult.class, notes = "根据酒店id查询酒店政策")
    @RequestMapping(value = "/queryhotelpolicy/{id}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    @ApiImplicitParam(required = true, name = "id", value = "酒店ID",paramType = "path")
    public ReturnResult queryHotelPolicy(@PathVariable Long id){
        if (StringUtils.isEmpty(id)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        SearchFacilitiesHotelVO facilitiesHotelVO = hotelService.getHotelPolicyByHotelId(id);
        if (StringUtils.isEmpty(facilitiesHotelVO)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        return ReturnResult.ok(facilitiesHotelVO);
    }
    //根据targetId查询酒店图片
    public ReturnResult getImgByTargetId(@PathVariable Long targetId) {
        if (StringUtils.isEmpty(targetId)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        List<ImageVO> imageVOList = imageService.getImageVOByHotelId(targetId);
        if (CollectionUtils.isEmpty(imageVOList)) {
            return ReturnResult.error(ErrorCodeEnum.BIZ_DATA_NULL);
        }
        return ReturnResult.ok(imageVOList);
    }
}
